package com.app.service.impl;


import com.app.common.EducationTool;
import com.app.mapper.CusEducationMapper;
import com.app.model.CusEducationModel;
import com.app.service.CusEducationService;
import com.app.service.CustomerService;
import com.app.service.UserService;
import com.app.vo.ValueAndNameVo;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;


/**
 * @Description:教育经历
 * @Author: N
 * @Date: 2022年11月24日 10点29分
 */
@Service
public class CusEducationServiceImpl implements CusEducationService {
    @Autowired
    UserService userService;
    @Autowired
    CusEducationMapper cusEducationMapper;
    @Autowired
    CustomerService customerService;
    @Autowired
    CusEducationService cusEducationService;

    @Override
    public int insert(CusEducationModel model) {
        return cusEducationMapper.insert(model);
    }

    @Override
    public void update(CusEducationModel model) {

        cusEducationMapper.updateById(model);
    }


    @Override
    public List<CusEducationModel> getEducationByCustomerId(int customerId) {
        QueryWrapper<CusEducationModel> queryWrapper = new QueryWrapper<>();
        queryWrapper.select().eq("customer_id", customerId).orderByDesc("education");
        List<CusEducationModel> userList = cusEducationMapper.selectList(queryWrapper);
        if (userList.isEmpty()) {
            return null;
        } else {
            return userList;
        }

    }

    @Override
    public void delete(int id) {
        cusEducationMapper.deleteById(id);
    }

    @Override
    public List<CusEducationModel> getWorkExpList(int customerId) {

        QueryWrapper<CusEducationModel> queryWrapper = new QueryWrapper<>();
        queryWrapper.select("id", "school_name", "education", "major", "start_time", "end_time").eq("customer_id", customerId);
        List<CusEducationModel> CusEducationList = cusEducationMapper.selectList(queryWrapper);
        if (CusEducationList.isEmpty()) {
            return null;
        } else {
            return CusEducationList;
        }
    }

    @Override
    //根据ID查询教育经历
    public Object getWorkExp(HttpServletRequest request) {
        String id = request.getParameter("id");
        CusEducationModel model = cusEducationMapper.selectById(id);
        if (model != null) {
            return model;
        }
        return null;
    }

    @Override
    public List<ValueAndNameVo> educationPie() {
        List<ValueAndNameVo> vo = new ArrayList<>();
        for (int k = 0; k < EducationTool.EDUCATION_VO_LIST.size(); k++) {
            QueryWrapper<CusEducationModel> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("education", EducationTool.EDUCATION_VO_LIST.get(k).getId());
            Integer count = cusEducationMapper.selectCount(queryWrapper);
            ValueAndNameVo vo1 = new ValueAndNameVo();
            vo1.setName(EducationTool.EDUCATION_VO_LIST.get(k).getData());
            vo1.setValue(count * 3);
            vo.add(vo1);
        }
        return vo;
    }

    @Override
    public ValueAndNameVo education() {
        int[] arr = new int[EducationTool.EDUCATION_VO_LIST.size()];
        String[] strings = new String[EducationTool.EDUCATION_VO_LIST.size()];
        for (int k = 0; k < EducationTool.EDUCATION_VO_LIST.size(); k++) {
            QueryWrapper<CusEducationModel> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("education", EducationTool.EDUCATION_VO_LIST.get(k).getId());
            Integer count = cusEducationMapper.selectCount(queryWrapper);
            strings[k] = EducationTool.EDUCATION_VO_LIST.get(k).getData();
            arr[k] = count;
        }
        ValueAndNameVo vo = new ValueAndNameVo();
        vo.setArr(arr);
        vo.setStrings(strings);
        return vo;
    }
}
